<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::Inflector</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::Inflector</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activesupport/lib/active_support/inflector_rb.html">
                vendor/rails/activesupport/lib/active_support/inflector.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
The <a href="Inflector.html">Inflector</a> transforms words from singular
to plural, class names to table names, modularized class names to ones
without, and class names to foreign keys. The default <a
href="Inflector.html#M000376">inflections</a> for pluralization,
singularization, and uncountable words are kept in inflections.rb.
</p>
<p>
The <a href="../Rails.html">Rails</a> core team has stated patches for the
<a href="Inflector.html#M000376">inflections</a> library will not be
accepted in order to avoid breaking legacy applications which may be
relying on errant <a href="Inflector.html#M000376">inflections</a>. If you
discover an incorrect inflection and require it for your application,
you&#8216;ll need to correct it yourself (explained below).
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000379">camelize</a>&nbsp;&nbsp;
      <a href="#M000389">classify</a>&nbsp;&nbsp;
      <a href="#M000391">constantize</a>&nbsp;&nbsp;
      <a href="#M000382">dasherize</a>&nbsp;&nbsp;
      <a href="#M000384">demodulize</a>&nbsp;&nbsp;
      <a href="#M000390">foreign_key</a>&nbsp;&nbsp;
      <a href="#M000383">humanize</a>&nbsp;&nbsp;
      <a href="#M000376">inflections</a>&nbsp;&nbsp;
      <a href="#M000392">ordinalize</a>&nbsp;&nbsp;
      <a href="#M000385">parameterize</a>&nbsp;&nbsp;
      <a href="#M000377">pluralize</a>&nbsp;&nbsp;
      <a href="#M000378">singularize</a>&nbsp;&nbsp;
      <a href="#M000388">tableize</a>&nbsp;&nbsp;
      <a href="#M000380">titleize</a>&nbsp;&nbsp;
      <a href="#M000387">transliterate</a>&nbsp;&nbsp;
      <a href="#M000386">transliterate</a>&nbsp;&nbsp;
      <a href="#M000381">underscore</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="Inflector/Inflections.html" class="link">ActiveSupport::Inflector::Inflections</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000379" class="method-detail">
        <a name="M000379"></a>

        <div class="method-heading">
          <a href="#M000379" class="method-signature">
          <span class="method-name">camelize</span><span class="method-args">(lower_case_and_underscored_word, first_letter_in_uppercase = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
By default, <tt><a href="Inflector.html#M000379">camelize</a></tt> converts
strings to UpperCamelCase. If the argument to <tt><a
href="Inflector.html#M000379">camelize</a></tt> is set to <tt>:lower</tt>
then <tt><a href="Inflector.html#M000379">camelize</a></tt> produces
lowerCamelCase.
</p>
<p>
<tt><a href="Inflector.html#M000379">camelize</a></tt> will also convert
&#8217;/&#8217; to &#8217;::&#8217; which is useful for converting paths to
namespaces.
</p>
<p>
Examples:
</p>
<pre>
  &quot;active_record&quot;.camelize                # =&gt; &quot;ActiveRecord&quot;
  &quot;active_record&quot;.camelize(:lower)        # =&gt; &quot;activeRecord&quot;
  &quot;active_record/errors&quot;.camelize         # =&gt; &quot;ActiveRecord::Errors&quot;
  &quot;active_record/errors&quot;.camelize(:lower) # =&gt; &quot;activeRecord::Errors&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000379-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000379-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 178</span>
178:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">camelize</span>(<span class="ruby-identifier">lower_case_and_underscored_word</span>, <span class="ruby-identifier">first_letter_in_uppercase</span> = <span class="ruby-keyword kw">true</span>)
179:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">first_letter_in_uppercase</span>
180:         <span class="ruby-identifier">lower_case_and_underscored_word</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\/(.?)/</span>) { <span class="ruby-node">&quot;::#{$1.upcase}&quot;</span> }.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/(?:^|_)(.)/</span>) { <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">upcase</span> }
181:       <span class="ruby-keyword kw">else</span>
182:         <span class="ruby-identifier">lower_case_and_underscored_word</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">camelize</span>(<span class="ruby-identifier">lower_case_and_underscored_word</span>)[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
183:       <span class="ruby-keyword kw">end</span>
184:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000389" class="method-detail">
        <a name="M000389"></a>

        <div class="method-heading">
          <a href="#M000389" class="method-signature">
          <span class="method-name">classify</span><span class="method-args">(table_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a class name from a plural table name like <a
href="../Rails.html">Rails</a> does for table names to models. Note that
this returns a string and not a Class. (To convert to an actual class
follow <tt><a href="Inflector.html#M000389">classify</a></tt> with <tt><a
href="Inflector.html#M000391">constantize</a></tt>.)
</p>
<p>
Examples:
</p>
<pre>
  &quot;egg_and_hams&quot;.classify # =&gt; &quot;EggAndHam&quot;
  &quot;posts&quot;.classify        # =&gt; &quot;Post&quot;
</pre>
<p>
Singular names are not handled correctly:
</p>
<pre>
  &quot;business&quot;.classify     # =&gt; &quot;Busines&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000389-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000389-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 309</span>
309:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">classify</span>(<span class="ruby-identifier">table_name</span>)
310:       <span class="ruby-comment cmt"># strip out any leading schema name</span>
311:       <span class="ruby-identifier">camelize</span>(<span class="ruby-identifier">singularize</span>(<span class="ruby-identifier">table_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">/.*\./</span>, <span class="ruby-value str">''</span>)))
312:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000391" class="method-detail">
        <a name="M000391"></a>

        <div class="method-heading">
          <a href="#M000391" class="method-signature">
          <span class="method-name">constantize</span><span class="method-args">(camel_cased_word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Tries to find a constant with the name specified in the argument string:
</p>
<pre>
  &quot;Module&quot;.constantize     # =&gt; Module
  &quot;Test::Unit&quot;.constantize # =&gt; Test::Unit
</pre>
<p>
The name is assumed to be the one of a top-level constant, no matter
whether it starts with &quot;::&quot; or not. No lexical context is taken
into account:
</p>
<pre>
  C = 'outside'
  module M
    C = 'inside'
    C               # =&gt; 'inside'
    &quot;C&quot;.constantize # =&gt; 'outside', same as ::C
  end
</pre>
<p>
NameError is raised when the name is not in CamelCase or the constant is
unknown.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000391-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000391-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 346</span>
346:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">constantize</span>(<span class="ruby-identifier">camel_cased_word</span>)
347:         <span class="ruby-identifier">names</span> = <span class="ruby-identifier">camel_cased_word</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'::'</span>)
348:         <span class="ruby-identifier">names</span>.<span class="ruby-identifier">shift</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">names</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">names</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">empty?</span>
349: 
350:         <span class="ruby-identifier">constant</span> = <span class="ruby-constant">Object</span>
351:         <span class="ruby-identifier">names</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
352:           <span class="ruby-identifier">constant</span> = <span class="ruby-identifier">constant</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">constant</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">constant</span>.<span class="ruby-identifier">const_missing</span>(<span class="ruby-identifier">name</span>)
353:         <span class="ruby-keyword kw">end</span>
354:         <span class="ruby-identifier">constant</span>
355:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000382" class="method-detail">
        <a name="M000382"></a>

        <div class="method-heading">
          <a href="#M000382" class="method-signature">
          <span class="method-name">dasherize</span><span class="method-args">(underscored_word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Replaces underscores with dashes in the string.
</p>
<p>
Example:
</p>
<pre>
  &quot;puni_puni&quot; # =&gt; &quot;puni-puni&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000382-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000382-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 218</span>
218:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dasherize</span>(<span class="ruby-identifier">underscored_word</span>)
219:       <span class="ruby-identifier">underscored_word</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/_/</span>, <span class="ruby-value str">'-'</span>)
220:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000384" class="method-detail">
        <a name="M000384"></a>

        <div class="method-heading">
          <a href="#M000384" class="method-signature">
          <span class="method-name">demodulize</span><span class="method-args">(class_name_in_module)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Removes the module part from the expression in the string.
</p>
<p>
Examples:
</p>
<pre>
  &quot;ActiveRecord::CoreExtensions::String::Inflections&quot;.demodulize # =&gt; &quot;Inflections&quot;
  &quot;Inflections&quot;.demodulize                                       # =&gt; &quot;Inflections&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000384-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000384-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 240</span>
240:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">demodulize</span>(<span class="ruby-identifier">class_name_in_module</span>)
241:       <span class="ruby-identifier">class_name_in_module</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/^.*::/</span>, <span class="ruby-value str">''</span>)
242:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000390" class="method-detail">
        <a name="M000390"></a>

        <div class="method-heading">
          <a href="#M000390" class="method-signature">
          <span class="method-name">foreign_key</span><span class="method-args">(class_name, separate_class_name_and_id_with_underscore = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a foreign key name from a class name.
<tt>separate_class_name_and_id_with_underscore</tt> sets whether the method
should put &#8216;_&#8217; between the name and &#8216;id&#8217;.
</p>
<p>
Examples:
</p>
<pre>
  &quot;Message&quot;.foreign_key        # =&gt; &quot;message_id&quot;
  &quot;Message&quot;.foreign_key(false) # =&gt; &quot;messageid&quot;
  &quot;Admin::Post&quot;.foreign_key    # =&gt; &quot;post_id&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000390-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000390-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 322</span>
322:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">foreign_key</span>(<span class="ruby-identifier">class_name</span>, <span class="ruby-identifier">separate_class_name_and_id_with_underscore</span> = <span class="ruby-keyword kw">true</span>)
323:       <span class="ruby-identifier">underscore</span>(<span class="ruby-identifier">demodulize</span>(<span class="ruby-identifier">class_name</span>)) <span class="ruby-operator">+</span> (<span class="ruby-identifier">separate_class_name_and_id_with_underscore</span> <span class="ruby-value">? </span><span class="ruby-value str">&quot;_id&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;id&quot;</span>)
324:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000383" class="method-detail">
        <a name="M000383"></a>

        <div class="method-heading">
          <a href="#M000383" class="method-signature">
          <span class="method-name">humanize</span><span class="method-args">(lower_case_and_underscored_word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Capitalizes the first word and turns underscores into spaces and strips a
trailing &quot;_id&quot;, if any. Like <tt><a
href="Inflector.html#M000380">titleize</a></tt>, this is meant for creating
pretty output.
</p>
<p>
Examples:
</p>
<pre>
  &quot;employee_salary&quot; # =&gt; &quot;Employee salary&quot;
  &quot;author_id&quot;       # =&gt; &quot;Author&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000383-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000383-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 228</span>
228:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">humanize</span>(<span class="ruby-identifier">lower_case_and_underscored_word</span>)
229:       <span class="ruby-identifier">result</span> = <span class="ruby-identifier">lower_case_and_underscored_word</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">dup</span>
230: 
231:       <span class="ruby-identifier">inflections</span>.<span class="ruby-identifier">humans</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>)<span class="ruby-operator">|</span> <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>) }
232:       <span class="ruby-identifier">result</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/_id$/</span>, <span class="ruby-value str">&quot;&quot;</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/_/</span>, <span class="ruby-value str">&quot; &quot;</span>).<span class="ruby-identifier">capitalize</span>
233:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000376" class="method-detail">
        <a name="M000376"></a>

        <div class="method-heading">
          <a href="#M000376" class="method-signature">
          <span class="method-name">inflections</span><span class="method-args">() {|Inflections.instance| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Yields a singleton instance of <a
href="Inflector/Inflections.html">Inflector::Inflections</a> so you can
specify additional inflector rules.
</p>
<p>
Example:
</p>
<pre>
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.uncountable &quot;rails&quot;
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000376-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000376-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 122</span>
122:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inflections</span>
123:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
124:         <span class="ruby-keyword kw">yield</span> <span class="ruby-constant">Inflections</span>.<span class="ruby-identifier">instance</span>
125:       <span class="ruby-keyword kw">else</span>
126:         <span class="ruby-constant">Inflections</span>.<span class="ruby-identifier">instance</span>
127:       <span class="ruby-keyword kw">end</span>
128:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000392" class="method-detail">
        <a name="M000392"></a>

        <div class="method-heading">
          <a href="#M000392" class="method-signature">
          <span class="method-name">ordinalize</span><span class="method-args">(number)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Turns a number into an ordinal string used to denote the position in an
ordered sequence such as 1st, 2nd, 3rd, 4th.
</p>
<p>
Examples:
</p>
<pre>
  ordinalize(1)     # =&gt; &quot;1st&quot;
  ordinalize(2)     # =&gt; &quot;2nd&quot;
  ordinalize(1002)  # =&gt; &quot;1002nd&quot;
  ordinalize(1003)  # =&gt; &quot;1003rd&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000392-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000392-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 377</span>
377:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ordinalize</span>(<span class="ruby-identifier">number</span>)
378:       <span class="ruby-keyword kw">if</span> (<span class="ruby-value">11</span><span class="ruby-operator">..</span><span class="ruby-value">13</span>).<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">number</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">%</span> <span class="ruby-value">100</span>)
379:         <span class="ruby-node">&quot;#{number}th&quot;</span>
380:       <span class="ruby-keyword kw">else</span>
381:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">number</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">%</span> <span class="ruby-value">10</span>
382:           <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>; <span class="ruby-node">&quot;#{number}st&quot;</span>
383:           <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>; <span class="ruby-node">&quot;#{number}nd&quot;</span>
384:           <span class="ruby-keyword kw">when</span> <span class="ruby-value">3</span>; <span class="ruby-node">&quot;#{number}rd&quot;</span>
385:           <span class="ruby-keyword kw">else</span>    <span class="ruby-node">&quot;#{number}th&quot;</span>
386:         <span class="ruby-keyword kw">end</span>
387:       <span class="ruby-keyword kw">end</span>
388:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000385" class="method-detail">
        <a name="M000385"></a>

        <div class="method-heading">
          <a href="#M000385" class="method-signature">
          <span class="method-name">parameterize</span><span class="method-args">(string, sep = '-')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Replaces special characters in a string so that it may be used as part of a
&#8216;pretty&#8217; URL.
</p>
<h4>Examples</h4>
<pre>
  class Person
    def to_param
      &quot;#{id}-#{name.parameterize}&quot;
    end
  end

  @person = Person.find(1)
  # =&gt; #&lt;Person id: 1, name: &quot;Donald E. Knuth&quot;&gt;

  &lt;%= link_to(@person.name, person_path %&gt;
  # =&gt; &lt;a href=&quot;/person/1-donald-e-knuth&quot;&gt;Donald E. Knuth&lt;/a&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000385-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000385-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 259</span>
259:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parameterize</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">sep</span> = <span class="ruby-value str">'-'</span>)
260:       <span class="ruby-identifier">re_sep</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">sep</span>)
261:       <span class="ruby-comment cmt"># replace accented chars with ther ascii equivalents</span>
262:       <span class="ruby-identifier">parameterized_string</span> = <span class="ruby-identifier">transliterate</span>(<span class="ruby-identifier">string</span>)
263:       <span class="ruby-comment cmt"># Turn unwanted chars into the seperator</span>
264:       <span class="ruby-identifier">parameterized_string</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/[^a-z0-9\-_\+]+/i</span>, <span class="ruby-identifier">sep</span>)
265:       <span class="ruby-comment cmt"># No more than one of the separator in a row.</span>
266:       <span class="ruby-identifier">parameterized_string</span>.<span class="ruby-identifier">squeeze!</span>(<span class="ruby-identifier">sep</span>)
267:       <span class="ruby-comment cmt"># Remove leading/trailing separator.</span>
268:       <span class="ruby-identifier">parameterized_string</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-node">/^#{re_sep}|#{re_sep}$/i</span>, <span class="ruby-value str">''</span>)
269:       <span class="ruby-identifier">parameterized_string</span>.<span class="ruby-identifier">downcase</span>
270:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000377" class="method-detail">
        <a name="M000377"></a>

        <div class="method-heading">
          <a href="#M000377" class="method-signature">
          <span class="method-name">pluralize</span><span class="method-args">(word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the plural form of the word in the string.
</p>
<p>
Examples:
</p>
<pre>
  &quot;post&quot;.pluralize             # =&gt; &quot;posts&quot;
  &quot;octopus&quot;.pluralize          # =&gt; &quot;octopi&quot;
  &quot;sheep&quot;.pluralize            # =&gt; &quot;sheep&quot;
  &quot;words&quot;.pluralize            # =&gt; &quot;words&quot;
  &quot;CamelOctopus&quot;.pluralize     # =&gt; &quot;CamelOctopi&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000377-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000377-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 138</span>
138:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pluralize</span>(<span class="ruby-identifier">word</span>)
139:       <span class="ruby-identifier">result</span> = <span class="ruby-identifier">word</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">dup</span>
140: 
141:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">word</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">inflections</span>.<span class="ruby-identifier">uncountables</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">result</span>.<span class="ruby-identifier">downcase</span>)
142:         <span class="ruby-identifier">result</span>
143:       <span class="ruby-keyword kw">else</span>
144:         <span class="ruby-identifier">inflections</span>.<span class="ruby-identifier">plurals</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>)<span class="ruby-operator">|</span> <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>) }
145:         <span class="ruby-identifier">result</span>
146:       <span class="ruby-keyword kw">end</span>
147:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000378" class="method-detail">
        <a name="M000378"></a>

        <div class="method-heading">
          <a href="#M000378" class="method-signature">
          <span class="method-name">singularize</span><span class="method-args">(word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The reverse of <tt><a href="Inflector.html#M000377">pluralize</a></tt>,
returns the singular form of a word in a string.
</p>
<p>
Examples:
</p>
<pre>
  &quot;posts&quot;.singularize            # =&gt; &quot;post&quot;
  &quot;octopi&quot;.singularize           # =&gt; &quot;octopus&quot;
  &quot;sheep&quot;.singluarize            # =&gt; &quot;sheep&quot;
  &quot;word&quot;.singularize             # =&gt; &quot;word&quot;
  &quot;CamelOctopi&quot;.singularize      # =&gt; &quot;CamelOctopus&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000378-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000378-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 157</span>
157:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">singularize</span>(<span class="ruby-identifier">word</span>)
158:       <span class="ruby-identifier">result</span> = <span class="ruby-identifier">word</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">dup</span>
159: 
160:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">inflections</span>.<span class="ruby-identifier">uncountables</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">result</span>.<span class="ruby-identifier">downcase</span>)
161:         <span class="ruby-identifier">result</span>
162:       <span class="ruby-keyword kw">else</span>
163:         <span class="ruby-identifier">inflections</span>.<span class="ruby-identifier">singulars</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>)<span class="ruby-operator">|</span> <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">replacement</span>) }
164:         <span class="ruby-identifier">result</span>
165:       <span class="ruby-keyword kw">end</span>
166:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000388" class="method-detail">
        <a name="M000388"></a>

        <div class="method-heading">
          <a href="#M000388" class="method-signature">
          <span class="method-name">tableize</span><span class="method-args">(class_name)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create the name of a table like <a href="../Rails.html">Rails</a> does for
models to table names. This method uses the <tt><a
href="Inflector.html#M000377">pluralize</a></tt> method on the last word in
the string.
</p>
<p>
Examples
</p>
<pre>
  &quot;RawScaledScorer&quot;.tableize # =&gt; &quot;raw_scaled_scorers&quot;
  &quot;egg_and_ham&quot;.tableize     # =&gt; &quot;egg_and_hams&quot;
  &quot;fancyCategory&quot;.tableize   # =&gt; &quot;fancy_categories&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000388-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000388-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 295</span>
295:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">tableize</span>(<span class="ruby-identifier">class_name</span>)
296:       <span class="ruby-identifier">pluralize</span>(<span class="ruby-identifier">underscore</span>(<span class="ruby-identifier">class_name</span>))
297:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000380" class="method-detail">
        <a name="M000380"></a>

        <div class="method-heading">
          <a href="#M000380" class="method-signature">
          <span class="method-name">titleize</span><span class="method-args">(word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Capitalizes all the words and replaces some characters in the string to
create a nicer looking title. <tt><a
href="Inflector.html#M000380">titleize</a></tt> is meant for creating
pretty output. It is not used in the <a href="../Rails.html">Rails</a>
internals.
</p>
<p>
<tt><a href="Inflector.html#M000380">titleize</a></tt> is also aliased as
as <tt>titlecase</tt>.
</p>
<p>
Examples:
</p>
<pre>
  &quot;man from the boondocks&quot;.titleize # =&gt; &quot;Man From The Boondocks&quot;
  &quot;x-men: the last stand&quot;.titleize  # =&gt; &quot;X Men: The Last Stand&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000380-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000380-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 195</span>
195:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">titleize</span>(<span class="ruby-identifier">word</span>)
196:       <span class="ruby-identifier">humanize</span>(<span class="ruby-identifier">underscore</span>(<span class="ruby-identifier">word</span>)).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\b('?[a-z])/</span>) { <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">capitalize</span> }
197:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000387" class="method-detail">
        <a name="M000387"></a>

        <div class="method-heading">
          <a href="#M000387" class="method-signature">
          <span class="method-name">transliterate</span><span class="method-args">(string)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000387-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000387-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 282</span>
282:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">transliterate</span>(<span class="ruby-identifier">string</span>)
283:         <span class="ruby-identifier">string</span>.<span class="ruby-identifier">mb_chars</span>.<span class="ruby-identifier">normalize</span>(<span class="ruby-identifier">:kd</span>). <span class="ruby-comment cmt"># Decompose accented characters</span>
284:           <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[^\x00-\x7F]+/</span>, <span class="ruby-value str">''</span>)     <span class="ruby-comment cmt"># Remove anything non-ASCII entirely (e.g. diacritics).</span>
285:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000386" class="method-detail">
        <a name="M000386"></a>

        <div class="method-heading">
          <a href="#M000386" class="method-signature">
          <span class="method-name">transliterate</span><span class="method-args">(string)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Replaces accented characters with their ascii equivalents.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000386-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000386-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 274</span>
274:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">transliterate</span>(<span class="ruby-identifier">string</span>)
275:       <span class="ruby-constant">Iconv</span>.<span class="ruby-identifier">iconv</span>(<span class="ruby-value str">'ascii//ignore//translit'</span>, <span class="ruby-value str">'utf-8'</span>, <span class="ruby-identifier">string</span>).<span class="ruby-identifier">to_s</span>
276:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000381" class="method-detail">
        <a name="M000381"></a>

        <div class="method-heading">
          <a href="#M000381" class="method-signature">
          <span class="method-name">underscore</span><span class="method-args">(camel_cased_word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The reverse of <tt><a href="Inflector.html#M000379">camelize</a></tt>.
Makes an underscored, lowercase form from the expression in the string.
</p>
<p>
Changes &#8217;::&#8217; to &#8217;/&#8217; to convert namespaces to paths.
</p>
<p>
Examples:
</p>
<pre>
  &quot;ActiveRecord&quot;.underscore         # =&gt; &quot;active_record&quot;
  &quot;ActiveRecord::Errors&quot;.underscore # =&gt; active_record/errors
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000381-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000381-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/inflector.rb, line 206</span>
206:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">underscore</span>(<span class="ruby-identifier">camel_cased_word</span>)
207:       <span class="ruby-identifier">camel_cased_word</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/::/</span>, <span class="ruby-value str">'/'</span>).
208:         <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/([A-Z]+)([A-Z][a-z])/</span>,<span class="ruby-value str">'\1_\2'</span>).
209:         <span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/([a-z\d])([A-Z])/</span>,<span class="ruby-value str">'\1_\2'</span>).
210:         <span class="ruby-identifier">tr</span>(<span class="ruby-value str">&quot;-&quot;</span>, <span class="ruby-value str">&quot;_&quot;</span>).
211:         <span class="ruby-identifier">downcase</span>
212:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>